/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');

    var toastr =require('toastr');

    app.useModule("ui.table");


    var datepicker = require('datepicker');
    app.controller('invest_listCtrl', ['$scope','$http','$filter' ,function ($scope, $http,$filter) {
        $scope.ctrlScope=$scope;
        $scope.orderParams = {
            url: "/admin/invest/recordList"
        };
        datepicker($scope);
        //全局查询
        $scope.search = function() {
            $scope.ctrlScope.itemsearch.beginDateTime= $scope.ctrlScope.itemsearch.beginDateTimex;
            $scope.ctrlScope.itemsearch.endDateTime= $scope.ctrlScope.itemsearch.endDateTimex;
            $scope.ctrlScope.itemsearch.beginDateTime=$filter('date')($scope.ctrlScope.itemsearch.beginDateTime,'yyyy-MM-dd');
            $scope.ctrlScope.itemsearch.endDateTime=$filter('date')($scope.ctrlScope.itemsearch.endDateTime,'yyyy-MM-dd');
            //表格查询参数设置
            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;
            //表格刷新
            $scope.orderParams.reload();
        };
        //全局查询重置
        $scope.reset=function(){
            $scope.orderParams.ajaxParam={};
            $scope.ctrlScope.itemsearch={};
            $scope.orderParams.reload();
        };
        //导出
        $scope.download=function(){
            var params=$scope.ctrlScope.itemsearch;
            $http.post("/admin/invest/excel/invest",params)
                .success(function (data){
                    console.info(data);
                    if(data.result=="success"){
                        window.open(data.file);
                    }else{
                        toastr.error("导出失败");
                    }
                }).error(function(data){

                });
        };
        //下载合同
        $scope.getContract=function(url){
            if(url){
                window.open(url);
            }else{
                toastr.error("下载失败");
            }
        };
    }]);


});